package com.fsy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fsy.entities.Book;
import com.fsy.service.BookService;
import com.fsy.mapper.BookMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 凡凡
* @description 针对表【book】的数据库操作Service实现
* @createDate 2022-03-15 10:27:51
*/
@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book>
    implements BookService{

    //引入mapper
    @Resource
    private BookMapper bookMapper;

    /**
     * 按条件查询图书
     * @param book
     * @return
     */
    @Override
    public List<Book> findByBook(Book book) {
        int page = book.getPage();
        int limit = book.getLimit();
        int offset = (page-1)*limit;
        book.setPage((page-1)*limit);
        book.setOffset(offset);//计算偏移量
        return bookMapper.findByBook(book);
    }

    /**
     * 查询全部图书条数
     * @param book
     * @return
     */
    public int selectBookCounts(Book book){
        return bookMapper.selectBookCounts(book);
    }
}




